package ar.com.fracervellera.server.repository.imp;

import java.util.List;

import javax.jdo.PersistenceManager;

import org.joda.time.DateTime;

import ar.com.fracervellera.model.Project;
import ar.com.fracervellera.server.repository.ProjectDAO;
import ar.com.fracervellera.web.command.ProjectForm;

public class ProjectDAOImp implements ProjectDAO {

	private static ProjectDAO projectDAO = null;
	
	private ProjectDAOImp() {
		super();
	}
	
	public static ProjectDAO getInstance(){
		if(projectDAO == null) {
			projectDAO = new ProjectDAOImp();
		}
		return projectDAO;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Project> getAllProjects(PersistenceManager pm) {
		String query = "select from " + Project.class.getName();
		return (List<Project>)pm.newQuery(query).execute();
	}

	@Override
	public Project create(ProjectForm project, PersistenceManager pm) {
		Project aux = new Project(project.getTitle(), project.getDescription(), project.getBlobKey(), project.getBlobKey(), project.getContentType(), project.getCreateDate());
		return pm.makePersistent(aux);
	}

	@Override
	public void delete(Project project, PersistenceManager pm) {
		 pm.deletePersistent(project);
	}


}
